package com.ccb.sc.message.controller;

import com.ccb.sc.auth.TokenAuth;
import com.ccb.sc.auth.TokenModel;
import com.ccb.sc.message.service.AppMessageService;
import com.ccb.sc.message.vo.MessageVo;
import com.ccb.sc.common.bind.annotation.CurrentUser;
import com.ccb.sc.common.bind.page.PageParams;
import com.ccb.sc.common.bind.page.PageVo;
import com.ccb.sc.common.bind.response.ResBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 会员消息表 前端控制器
 * </p>
 *
 * @author ken
 * @since 2022-08-14
 */
@TokenAuth
@RestController
@RequestMapping("/app/message")
@Api(value = "消息中心", tags = "消息中心")
public class MessageController {

    @Autowired
    private AppMessageService messageService;

    @GetMapping("/list")
    @ApiOperation(value = "消息列表", response = MessageVo.class, responseContainer = "list")
    public ResBody<?> list(@CurrentUser @ApiIgnore TokenModel token, PageParams queryParam) {
        PageVo<MessageVo> result = this.messageService.selectMessages(token.getId(), queryParam);
        return ResBody.success(result);
    }

    @GetMapping("/count")
    @ApiOperation(value = "是否有未读消息")
    public ResBody<?> count(@CurrentUser @ApiIgnore TokenModel token) {
        int countUnRead = this.messageService.countUnRead(token.getId());
        return ResBody.success(countUnRead);
    }
}
